package controllers

import (
    "github.com/beego/beego/v2/server/web"
    "volux/internal/services"
)

// BaseController 提供基础控制器功能
type BaseController struct {
    web.Controller
    bdevService    *services.BdevService
    subsysService  *services.SubsystemService
    storageService *services.StorageService
}

// Prepare 在每个action执行前调用
func (c *BaseController) Prepare() {
    // 初始化服务
    c.initServices()
}

func (c *BaseController) initServices() {
    c.bdevService = services.GetBdevService()
    c.subsysService = services.GetSubsystemService()
    c.storageService = services.GetStorageService()
}

// SuccessResponse 统一成功响应
func (c *BaseController) SuccessResponse(data interface{}) {
    c.Data["json"] = map[string]interface{}{
        "status": "success",
        "data":   data,
    }
    c.ServeJSON()
}

// ErrorResponse 统一错误响应
func (c *BaseController) ErrorResponse(code int, message string) {
    c.Ctx.Output.SetStatus(code)
    c.Data["json"] = map[string]interface{}{
        "status":  "error",
        "message": message,
    }
    c.ServeJSON()
}
